package com.jic.point.controller;
import com.jic.point.model.entity.ConfBdReconciliation;
import com.jic.point.model.vo.request.ConfBdReconciliationRequest;
import com.jic.point.model.vo.response.ConfBdReconciliationResponse;
import com.jic.point.model.vo.response.ConfBdResponse;
import com.jic.point.service.ConfBdReconciliationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.github.pagehelper.PageInfo;

import java.text.ParseException;
import java.util.List;
import com.jic.point.constant.consist.ResponseCode;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
/**
 * @Author: admin
 * @date: 2020-11-11 21:10:15
 */
 @RestController
 @Slf4j
 @RequestMapping("/confBdReconciliation")
 @Api(tags = " [BD对账表]控制类-PC")
public class ConfBdReconciliationController {
	@Autowired
	private ConfBdReconciliationService service;
	
	
     /**
      *新增记录
      * @param request 新增[BD对账表]请求参数
      * @return ConfBdReconciliationResponse 新增[BD对账表]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
    @ApiOperation(value = "新增[BD对账表]记录")
    @PostMapping("/save")
    @ResponseBody
    public RestResult<Long> save(@RequestBody ConfBdReconciliationRequest request) throws Throwable {
     		ConfBdReconciliation confBdReconciliation = new ConfBdReconciliation();
    		BeanUtils.copyProperties(request, confBdReconciliation);
    	    long flag = service.save(confBdReconciliation);
     return RestResult.success(flag);
    }
	
     /**
      * 新增或修改记录
      * @param request 新增或修改[BD对账表]请求参数
      * @return ConfBdReconciliationResponse 新增或修改[BD对账表]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "保存或更新[BD对账表]")
     @PostMapping("/saveOrUpdate")
      @ResponseBody
     public RestResult<Long> saveOrUpdate(@Validated @RequestBody ConfBdReconciliationRequest request) throws Throwable {
      		ConfBdReconciliation confBdReconciliation = new ConfBdReconciliation();
		     BeanUtils.copyProperties(request, confBdReconciliation);
	         long flag =   service.saveOrUpdate(confBdReconciliation);
      return RestResult.success(flag);
     }
	
     /**
      * 删除记录
      * @param request 删除[BD对账表]请求参数
      * @return ConfBdReconciliationResponse 删除[BD对账表]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "删除[BD对账表]记录")
     @PostMapping("/delete")
     @ResponseBody
     public RestResult<Long> delete(@RequestBody ConfBdReconciliationRequest request) throws Throwable {
      		ConfBdReconciliation confBdReconciliation = new ConfBdReconciliation();
	     	BeanUtils.copyProperties(request, confBdReconciliation);
	         long flag = service.deleteByPrimaryKeyLogically(confBdReconciliation);
      return RestResult.success(flag);
     }
	
     /**
      * 修改记录
      * @param request 修改[BD对账表]请求参数
      * @return ConfBdReconciliationResponse 修改[BD对账表]响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "修改[BD对账表]记录")
     @PostMapping("/update")
     @ResponseBody
     public RestResult<Long> update(@RequestBody ConfBdReconciliationRequest request) throws Throwable {
      		ConfBdReconciliation confBdReconciliation = new ConfBdReconciliation();
	     	BeanUtils.copyProperties(request, confBdReconciliation);
	         long flag = service.updateByPrimaryKeySelective(confBdReconciliation);
      return RestResult.success(flag);
     }
	
     /**
      * 单表查询详情信息
      * @param request 查询[BD对账表]详情请求参数
      * @return ConfBdReconciliationResponse 查询[BD对账表]详情响应参数
      * author admin
      * @date 2020-3-11 20:54:04
      */
      @PostMapping("/getByPrimaryKey")
      @ApiOperation(value = "查询[BD对账表]详情")
      @ResponseBody
     public RestResult<ConfBdReconciliationResponse> getByPrimaryKey(@Validated  @RequestBody ConfBdReconciliationRequest request) {
     	log.info("查询详情请求参数入参，{}", JSONObject.toJSONString(request));
	     if (request!=null && request.getId()!=null) {
	      
	     	ConfBdReconciliation confBdReconciliation = new ConfBdReconciliation();
	     	BeanUtils.copyProperties(request, confBdReconciliation);
	     	ConfBdReconciliation result = service.getByPrimaryKey(confBdReconciliation);
		     log.info("查询详情请求参数出参，{}", JSONObject.toJSONString(result));
		     if (result == null) {
		     	return RestResult.error(ResponseCode.EXCEPTION, "记录不存在");
		     }
		     ConfBdReconciliationResponse bo = new ConfBdReconciliationResponse();
		     BeanUtils.copyProperties(result, bo);
	     	return RestResult.success(bo);
	     }
     	log.info("查询详情请求结束");
	     return RestResult.success(new ConfBdReconciliationResponse());
     }
	
    /**
      * 分页查询
      *
      * @param request 分页查询请求参数
      * @return 分页列表
      * @throws Throwable 业务异常和系统异常
      */
     @PostMapping("/listPage")
     @ApiOperation(value = " 分页查询列表 ")
     @ResponseBody
     public RestResult<PageInfo<ConfBdReconciliation>> listPage (@RequestBody ConfBdReconciliationRequest request) throws Throwable {
      ConfBdReconciliation param = new ConfBdReconciliation();
      BeanUtils.copyProperties(request, param);
      param.setDeleteFlag(0);
     return RestResult.success(service.listPageBySelective(param, request.getPageNum(),request.getPageSize()));
     }
     
	
      /**
       *CONF_BD_RECONCILIATION 查询列表（不分页）
       * @param  request 前端请求参数
       */
      @PostMapping("/listAll")
      @ApiOperation(value = "不分页查询 [BD对账表] ")
      @ResponseBody
      public RestResult<List<ConfBdReconciliationResponse>>  listConfBdReconciliationAllRecord(@RequestBody ConfBdReconciliationRequest request) throws Throwable {
      		ConfBdReconciliation param = new ConfBdReconciliation();
	     	BeanUtils.copyProperties(request, param);
	     	param.setDeleteFlag(0);
	     	List<ConfBdReconciliation> list = service.listAllRecord(param);
			List<ConfBdReconciliationResponse> responseList = list.stream().map(temp -> {
			ConfBdReconciliationResponse bo = new ConfBdReconciliationResponse();
			BeanUtils.copyProperties(temp, bo);
			return bo;
			}).filter(item -> item != null).collect(Collectors.toList());
		    return RestResult.success(responseList);
      }
    /**
     *
     *
     * @description: 对账接口
     * @return:
     * @author: fengrui
     * @time: 2020/11/11 19:40
     */
    private RestResult querReconciliation() throws ParseException {
        service.querReconciliation();
        return RestResult.success(null);
    }


}

	
